﻿/// <reference path="jquery-1.5-vsdoc.js"/>
/// <reference path="jquery.json.js"/>
/// <reference path="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"/>

/// System Related

function createEnum(type, flags) {
    for (var i in type.prototype) {
        type[i] = type.prototype[i];
    }
    // __xxx props are msajax/vs talking to each other
    type.__enum = true;
    type.__flags = flags;
}

LocalRecordState = function () {
    /// <summary>
    /// LocalRecordState - Geeft de status van een local record aan
    /// </summary>
    /// <field name="Deleted" type="Number" integer="true" static="true" >Deleted</field>
    /// <field name="Unchanged" type="Number" integer="true" static="true">Unchanged</field>
    /// <field name="Updated" type="Number" integer="true" static="true" >Updated</field>
    /// <field name="New" type="Number" integer="true" static="true" >New</field>

    throw new Error("constructor not implemented. this is a static enum");
}
LocalRecordState.prototype = {
    Deleted: -1,
    Unchanged: 0,
    Updated: 1,
    New: 2
}
createEnum(LocalRecordState);

RemoteODataAction = function () {
    /// <summary>
    /// LocalRecordState - Geeft de status van een local record aan
    /// </summary>
    /// <field name="Create" type="Number" static="true" >Create</field>
    /// <field name="Read" type="Number" static="true" >Read</field>
    /// <field name="Update" type="Number" static="true">Update</field>
    /// <field name="Delete" type="String" static="true" >Delete</field>
    
    throw new Error("constructor not implemented. this is a static enum");
}
RemoteODataAction.prototype = {
    Create: "POST",
    Read: "GET",
    Update: "PUT",
    Delete: "DELETE"
}
createEnum(RemoteODataAction);

String.format = function () {
    var s = arguments[0];
    for (var i = 0; i < arguments.length - 1; i++) {
        var reg = new RegExp("\\{" + i + "\\}", "gm");
        s = s.replace(reg, arguments[i + 1]);
    }

    return s;
}

function getParameterByName(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

/// HTML5 Web Database Related


showMeTheMoney = function (tx, data) {
    alert(data);
}

errorMessage = function (tx, error) {
    alert('Failed to retrieve notes from database - ' + error.message);
    return;
}

function SQLResultSetRowListToArray(resultset) {
    var result = new Array();
    for (var i = 0; i < resultset.rows.length; ++i) {
        var row = resultset.rows.item(i);
        result.push(row);
    }
    return result;
}

/// DateTime Related

function DateDeserialize(dateStr) {
    return eval('new' + dateStr.replace(/\//g, ' '));
}


function DateToLocaleString(date) {
    return new Date(date).toLocaleDateString();
}

function toSimpleDateString(o) {
    var d = new Date(o);
    var day = d.getDate();
    if (d.getDate() < 10)
        day = String.format("0{0}", d.getDate());
    var m = d.getMonth() + 1;
    if (d.getMonth() + 1 < 10)
        m = String.format("0{0}", d.getMonth() + 1);
    return String.format("{0}-{1}-{2}", day, m, d.getFullYear());
}

function toSimpleDate(s) {
    var elems = s.split("-");
    var d = new Date();
    d.setDate(parseInt(elems[0]));
    d.setMonth(parseInt(elems[1]) - 1);
    d.setFullYear(parseInt(elems[2]));
    return d;
}

function HideNavBar() {
    setTimeout(scrollTo, 0, 0, 1);
}

function NavigateTo(url, paramName, paramObject) {
    localStorage.setItem(paramName, paramObject);
    window.location.href = url;
}